#!/bin/bash

export JAVA_HOME=/usr/java/jdk
TOMCAT_HOME=/opt/tomcat
TOMCAT_PORT=8080
PROJECT=jenkins

DATE=`date +%F`
TIME=`date +%F_%T`

TOMCAT_WAR_BAK=/opt/tomcat_war_bak
TOMCAT_WAR_TEMP=/opt/tomcat_war_temp

tomcat_pid=`/usr/sbin/lsof -n -P -t -i :$TOMCAT_PORT`

kill -9 $tomcat_pid


mkdir -p $TOMCAT_WAR_BAK/$DATE 2>/dev/null
cp $TOMCAT_HOME/webapps/$PROJECT.war  $TOMCAT_WAR_BAK/$DATE/$PROJECT.war.$TIME

rm -rf $PROJECT*

cp $TOMCAT_WAR_TEMP/$PROJECT.war  $TOMCAT_HOME/webapps/$PROJECT.war

su - tomcat -c "$TOMCAT_HOME/bin/startup.sh"



